﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T.SF.Console
{
    internal class AppConfigManager : IProviderConfigManager
    {
        
        public long GetHeartBeatTimeSpan()
        {
            string zookeeperStr = ConfigurationManager.AppSettings.Get("HSF.HeartBeatTimeSpan");

            if (string.IsNullOrEmpty(zookeeperStr))
                zookeeperStr = "10000";

            long result = 10000;
            long.TryParse(zookeeperStr, out result);

            return result;
 
        }

        public int GetMaxWorkerThreads()
        {
            string zookeeperStr = ConfigurationManager.AppSettings.Get("HSF.Max.WorkerThreads");

            if (string.IsNullOrEmpty(zookeeperStr))
                zookeeperStr = "1000";

            int result = 1000;
            int.TryParse(zookeeperStr, out result);

            return result;

        }

        public int GetMaxCompletionPortThreads()
        {
            string zookeeperStr = ConfigurationManager.AppSettings.Get("HSF.Max.CompletionPortThreads");

            if (string.IsNullOrEmpty(zookeeperStr))
                zookeeperStr = "200";

            int result = 200;
            int.TryParse(zookeeperStr, out result);

            return result;

        }

        public int GetMinWorkerThreads()
        {
            string zookeeperStr = ConfigurationManager.AppSettings.Get("HSF.Min.WorkerThreads");

            if (string.IsNullOrEmpty(zookeeperStr))
                zookeeperStr = "100";

            int result = 100;
            int.TryParse(zookeeperStr, out result);

            return result;

        }

        public int GetMinCompletionPortThreads()
        {
            string zookeeperStr = ConfigurationManager.AppSettings.Get("HSF.Min.CompletionPortThreads");

            if (string.IsNullOrEmpty(zookeeperStr))
                zookeeperStr = "20";

            int result = 20;
            int.TryParse(zookeeperStr, out result);

            return result;

        }

        public int GetFusingTPM()
        {
            string zookeeperStr = ConfigurationManager.AppSettings.Get("HSF.Fusing.MaxTPM");

            if (string.IsNullOrEmpty(zookeeperStr))
                zookeeperStr = "200";

            int result = 200;
            int.TryParse(zookeeperStr, out result);

            return result;
        }

        public int GetFusingCount()
        {
            string zookeeperStr = ConfigurationManager.AppSettings.Get("HSF.Fusing.Count");

            if (string.IsNullOrEmpty(zookeeperStr))
                zookeeperStr = "2";

            int result = 2;
            int.TryParse(zookeeperStr, out result);

            return result;
        }

        public int GetFusingTime()
        {
            string zookeeperStr = ConfigurationManager.AppSettings.Get("HSF.Fusing.Time");

            if (string.IsNullOrEmpty(zookeeperStr))
                zookeeperStr = "10";

            int result = 10;
            int.TryParse(zookeeperStr, out result);

            return result;
        }
    }
}
